<template>
<div id="app">
  <router-view></router-view>
</div>
</template>

<script type="text/ecmascript-6">
import API from "./API"
import router from "./router"
import {
  mapMutations,
  mapActions,
  mapState
} from 'vuex';
export default {
  name: 'app',
  componentName: "root",
  //        mixins: [mix],
  computed: {
    ...mapState({
      user: state => state.user
    }),
  },
  mounted() {
    this.checkuser();
  },
  methods: {
    ...mapActions([
      'setuser'
    ]),
    checkuser() {
      if (!this.user) {
        API.getUserMapBySeesion().then((res) => {
          var json = res.data;

          if (json.message == "success") {

            if (json.userinfo) {
              this.setuser({
                user: json.userinfo
              });
            } else {

              router.push({
                path: 'login'
              });
            }
          }
        }).catch((e) => {
          console.log(e)
        })
      }
    }
  }
}
</script>

<style>

</style>
